package com.briup.day25.Set;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

public class TreeSetDemo2 {
	
	public static void main(String[] args) {
		
		Comparator c = new Comparator() {
			public int compare(Object o1, Object o2) {
				//按照长度升序
				return (((String)o1).length() - ((String)o2).length());
			}
		};
		
		Set set = new TreeSet(c);
		
		set.add("gg");
		set.add("hiwrp");
		set.add("baoyanla");
		
		System.out.println(set.size());
		
		set.forEach(System.out::println);
	}

}

/*class MyComparator implements Comparator{
	
	public int compare(Object o1, Object o2) {
		//负值 o1在o2左侧 o1新插入元素
		//0 no
		int i1 = (int) o1;
		int i2 = (int) o2;
		if (i1 > i2) {
			return -1;
		}else {
			return 1;
		}
				
	}
	
 }*/